package com.example.book.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


/**
 *  AOP 练习, 统计每个  controller 的耗时
 */
@Aspect
@Component
@Slf4j
public class TextApect {
    @Around("execution(* com.example.book.controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long begin = System.currentTimeMillis();
        Object resutl = joinPoint.proceed();
        long end = System.currentTimeMillis();
        log.error(joinPoint +" 耗时:  " + (end - begin) + " ms");
        return resutl;
    }
}
